package com.kim.nidoya.utils;

import com.kim.nidoya.R;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.TextView;

public class DialogUtils {

	public interface PositiveCallback {
		void onPositiveButtonPressed();
	}

	public static Dialog generateDialog(Context context) {
		Builder builder = new Builder(context);
		Dialog dialog = builder.create();
		dialog.show();
		dialog.setCancelable(false);
		LayoutParams layoutParams = dialog.getWindow().getAttributes();
		layoutParams.alpha = 0.75f;
		dialog.getWindow().setAttributes(layoutParams);
		dialog.setCanceledOnTouchOutside(false);
		dialog.setContentView(R.layout.dialog_view);
		return dialog;
	}

	/**
	 * 显示对话框
	 * 
	 * @param context
	 * @param message
	 * @param clickListener
	 */
	public static void showDialog(Context context, String message,
			final PositiveCallback positiveCallback) {
		final Dialog dialog = generateDialog(context);
		TextView textView = (TextView) dialog.findViewById(R.id.dialog_msg);
		textView.setText(message);
		((Button) dialog.findViewById(R.id.btn_dialog_ok))
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						positiveCallback.onPositiveButtonPressed();
						dialog.dismiss();
					}
				});
		((Button) dialog.findViewById(R.id.btn_dialog_cancel))
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						dialog.dismiss();
					}
				});
	}

}
